module SeminarHelper
  
  $seminar_event = "Seminar"
  $PhD_defense = "PhD Defense"
  $Defense = "Defense"
  
  $at_rooms = []
  $classes = ["SI-003", "SI-004", "SI-006", "SI-007", "SI-008", "SI-013", "SI-015"]
  $type_list = ["Seminar", "PhD Defense", "Defense"]
  $time_offset = [0, 1, 6, 30]
  
  def query_seminars()  
    @seminars = []
  
    @seminars = select_events_in_range(30)
  
    return @seminars
  end
  
  
   def select_events_in_range(offset)
    current_time = Time.now
    add_time = (60 * 60 * 24)*offset
    in_a_time = current_time + add_time

    announcements = Announcement.find_by_sql("SELECT * FROM announcements WHERE announcement_type = 'Seminar' OR announcement_type = 'PhD Defense' OR announcement_type = 'Defense' order by start asc")
    counter = 0
    result = []
    announcements.each do |a|
      #Notice that here i change the time to integers since is much easier to check than the time object
      if(offset == 1) 
        if((a.end >= current_time) && (a.end.day == current_time.day))
          result[counter] = a
          counter+=1
        end
      elsif((a.end >= current_time) && (a.end <= in_a_time)) 
        result[counter] = a
        counter+=1
      end
    end
    return result
  end
  
end
